<?php

class SubscribeModel
{
    /**
     * Every model needs a database connection, passed to the model
     * @param object $db A PDO database connection
     * 
     * fetchAll() is the PDO method that gets all result rows, here in object-style because we defined this in
	 * libs/controller.php! If you prefer to get an associative array as the result, then do
	 * $query->fetchAll(PDO::FETCH_ASSOC); or change libs/controller.php's PDO options to
	 * $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ...
     */
		
	
    function __construct($db) {
        try {
            $this->db = $db;
        } catch (PDOException $e) {
            exit('Database connection could not be established.');
        }
    }

    public function addSubscribe($name,$email){
    	
        $name = strip_tags($name);
        $email = strip_tags($email);
    
    	$sql = "INSERT INTO tbl_subscribe (NAME,EMAIL) VALUES (:name,:email)";
    	$query = $this->db->prepare($sql);
    	$query->execute(array(':name' => $name,':email' => $email));
    }
}
